package com.ticket.sass.ticketserver.controller

import com.github.xiaoymin.knife4j.annotations.ApiSupport
import com.ticket.sass.common.ticketserver.dto.output.*
import com.ticket.sass.ticketserver.business.TradeBusiness
import com.ticket.sass.ticketserver.dto.input.OrderTicketRefundInput
import com.ticket.sass.ticketserver.dto.input.OrderTicketStatusInput
import com.ticket.sass.ticketserver.dto.input.OrderTicketSubmitInput
import com.ticket.sass.ticketserver.dto.input.SeatLockInput
import com.ticket.sass.ticketserver.dto.input.SeatUnlockInput
import com.ticket.sass.ticketserver.dto.output.ResultWrapOutput
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.web.bind.annotation.*
import javax.validation.Valid


/**
 * @author 朱其鹏
 * @date 2024/4/13 17:09
 */
@RestController
@RequestMapping("/trade")
@ApiSupport(order = 2)
@Api(tags = ["交易类接口"])
class TradeController(
    private val tradeBusiness: TradeBusiness,
) {
    @ApiOperation("座位锁定")
    @PostMapping("/seat-lock")
    fun seatLock(@Valid @RequestBody input: SeatLockInput): ResultWrapOutput<SeatLockOutput> {
        return ResultWrapOutput.success(tradeBusiness.seatLock(input))
    }

    @ApiOperation("座位解锁")
    @PostMapping("/seat-unlock")
    fun seatUnlock(@Valid @RequestBody input: SeatUnlockInput): ResultWrapOutput<SeatUnlockOutput> {
        return ResultWrapOutput.success(tradeBusiness.seatUnlock(input))
    }

    @ApiOperation("影票下单")
    @PostMapping("/order-tickets")
    fun orderTicket(@Valid @RequestBody input: OrderTicketSubmitInput): ResultWrapOutput<OrderTicketSubmitOutput> {
        return ResultWrapOutput.success(tradeBusiness.orderTicketSubmit(input))
    }

    @ApiOperation("影票订单状态")
    @GetMapping("/order-tickets/status")
    fun orderTicketStatus(@Valid input: OrderTicketStatusInput): ResultWrapOutput<OrderTicketStatusOutput> {
        return ResultWrapOutput.success(tradeBusiness.orderTicketStatus(input))
    }

    @ApiOperation("影票订单信息")
    @GetMapping("/order-tickets/{code}")
    fun orderTicketInfo(@Valid @PathVariable code: String): ResultWrapOutput<OrderTicketInfoOutput> {
        return ResultWrapOutput.success(tradeBusiness.orderTicketInfo(code))
    }

    @ApiOperation("影票订单退单")
    @PutMapping("/order-tickets/refund")
    fun orderTicketRefund(@RequestBody @Valid input: OrderTicketRefundInput): ResultWrapOutput<OrderTicketRefundOutput> {
        return ResultWrapOutput.success(tradeBusiness.orderTicketRefund(input))
    }
}